package cn.zqy.demo.day08;


import java.util.Scanner;

// 字符串练习题
public class Demo07StringPrictice {
    public static void main(String[] args) {
        int[] numArray = new int[]{1,2,3};
        // 1.数组{1,2,3}转化为[word1#word2#word3]
        String str =  printString(numArray);
        System.out.println(str);
        System.out.println("================");

        /** @ 键盘输入字符串，统计数字，大小写字母分别出现的次数 */
        Scanner sc = new Scanner(System.in);
        String s  = sc.next();
        int[] arr = totalnum(s);
        System.out.println("数字： " + arr[0]);
        System.out.println("大写" + arr[1]);
        System.out.println("小写" + arr[2]);
        System.out.println("其他" + arr[3]);
    }
    public static String printString(int[] arr) {
        String str = "[";
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                str = str + "word" + arr[i] + "]";
            } else {
                str = str + "word" + arr[i] + "#";
            }
        }
        return str;
    }
    public static int[] totalnum(String str) {
        char[] ch = str.toCharArray();
        int[] arr = new int[4];
        int number = 0;
        int upper = 0;
        int lower = 0;
        int other = 0;
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] >= '0' && ch[i] <= '9') {
                number ++;
            } else if(ch[i] >= 'a' && ch[i] <= 'z') {
                lower++;
            }  else if(ch[i] >= 'A' && ch[i] <= 'Z') {
                upper++;
            } else {
                other++;
            }
        }
        arr[0] = number;
        arr[1] = upper;
        arr[2] = lower;
        arr[3] = other;
        return arr;
    }
}
